<?php
require_once('includes/config.php');
require_once('includes/sessions.php');

$stat = $db -> Execute("SELECT id, page, rank, miejsce, user FROM players WHERE email='".$_SESSION['email']."'");
$czat = $db -> Execute("SELECT `gracz` FROM `chat_config` WHERE `gracz`=".$stat -> fields['id']);
if ($czat -> fields['gracz'])
{
	error (NO_PERM);
}
$czat -> Close();
$_POST['tekst'] = strip_tags($_POST['tekst']);
require_once('includes/bbcodegwiazdki.php');
$_POST['tekst'] = bbcodetohtml($_POST['tekst']);

$czas1 = date("H:i");

if ($stat -> fields['rank'] == 'Admin') 
{
	$starter = "<span style=\"color: royalblue;\">".$stat -> fields['user']."</span>";
} 
elseif ($stat -> fields['rank'] == 'Kapitan Gwardii') 
{
	$starter = "<span style=\"color: #FF8000;\">".$stat -> fields['user']."</span>";
} 
elseif  ($stat -> fields['rank'] == 'Namiestnik') 
{
	$starter = "<span style=\"color: #8080FE;\">".$stat -> fields['user']."</span>";
} 
elseif ($stat -> fields['rank'] == 'Staff') 
{
	$starter = "<span style=\"color: orange;\">".$stat -> fields['user']."</span>";
} 
elseif ($stat -> fields['rank'] == 'Karczmarka' || $stat -> fields['rank'] == 'Mistrz Gry') 
{
	$starter = "<span style=\"color: darkgreen;\">".$stat -> fields['user']."</span>";
} else	$starter = $stat -> fields['user'];



$db -> Execute("INSERT INTO `chat` (`user`, `chat`, `senderid`, `ownerid`, `czas`, `lokacja`) VALUES('".$starter."', '".$_POST['tekst']."', ".$stat -> fields['id'].", 0, '".$czas1."', 'Altara')");

header("Location: karczma.php");

?>
